package com.kj.platformlogistics.home.adapter;

import android.graphics.Color;
import android.view.View;
import android.view.animation.LinearInterpolator;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kj.platformlogistics.R;
import com.kj.platformlogistics.home.model.HomeHistoryOrderList;

import java.util.List;

import me.samlss.broccoli.Broccoli;
import me.samlss.broccoli.BroccoliGradientDrawable;
import me.samlss.broccoli.PlaceholderParameter;

public class HomeHistoryOrderAdapter extends BaseQuickAdapter<HomeHistoryOrderList.ResultDTO, BaseViewHolder> {

    public HomeHistoryOrderAdapter(@Nullable List<HomeHistoryOrderList.ResultDTO> data) {
        super(R.layout.item_home_historyorder, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeHistoryOrderList.ResultDTO item) {


        Broccoli broccoli = null;
        if (broccoli == null){
            broccoli = new Broccoli();
        }

        broccoli.removeAllPlaceholders();
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvTitleStatus))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvStatus))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvOrderNumber))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvOrderCreateTime))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());

        broccoli.show();


        Runnable task = null;
        if (task == null){
            final Broccoli finalBroccoli = broccoli;
            task = new Runnable() {
                @Override
                public void run() {
                    finalBroccoli.removeAllPlaceholders();

                    if (item==null){
                        return;
                    }

                    switch (item.getStatus()){
                        case -1:
                            helper.setText(R.id.tvTitleStatus,"订单已取消");
                            helper.setText(R.id.tvStatus,"订单状态：已取消");
                            break;
                        case 0:
                            helper.setText(R.id.tvTitleStatus,"订单待揽件");
                            helper.setText(R.id.tvStatus,"订单状态：待揽件");
                            break;
                        case 1:
                            helper.setText(R.id.tvTitleStatus,"订单已揽件");
                            helper.setText(R.id.tvStatus,"订单状态：已揽件");
                            break;
                        case 2:
                            helper.setText(R.id.tvTitleStatus,"订单待派送");
                            helper.setText(R.id.tvStatus,"订单状态：待派送");
                            break;
                        case 3:
                            helper.setText(R.id.tvTitleStatus,"订单派送中");
                            helper.setText(R.id.tvStatus,"订单状态：派送中");
                            break;
                        case 4:
                            helper.setText(R.id.tvTitleStatus,"订单已完成");
                            helper.setText(R.id.tvStatus,"订单状态：已完成");
                            break;
                    }
                    helper.setText(R.id.tvOrderNumber,"订单编号："+item.getWaybillNumber());
                    helper.setText(R.id.tvOrderCreateTime,item.getCreateTime()==null?"":item.getCreateTime());
                }
            };
        }else{
            helper.itemView.removeCallbacks(task);
        }
        helper.itemView.postDelayed(task, 1000);





    }
}
